<template>
	<view>
		<view v-if="title" class="gui-padding">
			<text :class="titleClass" class="gui-h6 gui-color-black">{{title}}</text>
		</view>
		<view class="gui-padding-middle-small gui-bg-white">
			<view class="gui-grid">
				<view @tap="click(item)" class="gui-grid-item" :style="{'flex':'0 0 ' + 100/columns + '%'}"
					v-for="(item, index) in items" :key="index">

					<text v-if="item.icon" class="gui-icons gui-block gui-color-blue gui-text" v-html="item.icon"
						:style="{'fontSize':width + 'rpx'}"></text>
					<view v-else class="img-radius-wrapper">
						<image :src="item[keys[0]]" :style="{width: width + 'rpx', height: width + 'rpx'}"
							class="img-radius-img" mode="aspectFill" />
					</view>
					<text style="max-width: 160rpx;display: inline-block;"
						class="gui-text-small gui-text-center">{{item[keys[1]]}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "hyb-grid",

		props: {
			items: {
				type: Array,
				default: () => {
					return []
				}
			},

			titleClass: {
				type: Array,
				default: () => {
					return []
				}
			},
			columns: {
				type: Number,
				default: 5
			},

			width: {
				type: Number,
				default: 56
			},

			title: {
				type: String,
				default: null
			},
			keys: {
				type: Array,
				default: ['img', 'name']
			}
		},
		data() {
			return {

			};
		},
		methods: {
			click(item) {
				this.$emit("item_click", item);
			},

		}
	}
</script>

<style>
	.gui-grid-item {
		padding: 20rpx 0;
	}

	.gui-ic-image {
		border-radius: 10rpx;
		margin-bottom: 10rpx;
	}

	.gui-list-image {
		width: 360rpx;
		height: 360rpx;
	}

	.img-radius-wrapper {
		border-radius: 16rpx;
		overflow: hidden;
		width: 100%;
		height: auto;
		display: flex;
		justify-content: center;
	}

	.img-radius-img {
		width: 100%;
		height: 100%;
		display: block;
		border-radius: 8px;
	}
</style>